<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

自动过滤左右空格
<input type="text" onmouseout="method()" id="text"/>

</body>

<script>

    var elementById = document.getElementById("text");

    function method() {
        elementById.value = elementById.value.trim();

    }


</script>
</html>